package tr.com.netgis.web;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Hashtable;
import java.util.List;
import java.util.Vector;

import org.ksoap2.serialization.PropertyInfo;

import tr.com.netgis.pojo.DeviceData;
import tr.com.netgis.pojo.NGLocation;

public class SetLocationsRequest extends SetLocationRequest {

	private List<DeviceData> locations;

	public List<DeviceData> getLocations() {
		return locations;
	}

	public void setLocations(List<DeviceData> locations) {
		this.locations = locations;
	}

	public SetLocationsRequest(NGLocation... locations) {
		super();
		Collection<NGLocation> coll = new ArrayList<NGLocation>();
		Collections.addAll(coll, locations);
		init(coll);
	}

	private void init (Collection<NGLocation> locations) {
		this.locations = new Vector<DeviceData>();
		for (NGLocation ngLocation : locations) {
			DeviceData data = new DeviceData(ngLocation);
			this.locations.add(data);
		}		
	}
	
	public SetLocationsRequest(Collection<NGLocation> locations) {
		super();
		init(locations);
	}

	public static final int P_DATA_PACKAGE = 0;
	
	@Override
	public PropertyInfo getPropertyInfo(int index) {
		PropertyInfo info = new PropertyInfo();
		getPropertyInfo(index, null, info);
		return info;
	}

	@Override
	public Object getProperty(int index) {
		return this.locations;
	}

	@Override
	public int getPropertyCount() {
		return 1;
	}

	@SuppressWarnings("rawtypes")
	@Override
	public void getPropertyInfo(int index, Hashtable arg1, PropertyInfo info) {
		switch (index) {
		case P_DATA_PACKAGE:
			info.setType(PropertyInfo.VECTOR_CLASS);
			info.setName("dataPackage");
			info.setValue(getLocations());
			info.elementType = new PropertyInfo();
			info.elementType.type = DeviceData.class;
			info.elementType.name = "DeviceData";
			break;
		default:
			break;
		}
	}

	@SuppressWarnings({ "unchecked", "rawtypes" })
	@Override
	public void setProperty(int index, Object value) {
		switch (index) {
		case P_DATA_PACKAGE:
			this.locations = (List)value;
			break;
		default:
			break;
		}
	}
	
	
	
	
}
